package models

import (
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

var DB *gorm.DB

func MysqlInit() {
	var err error
	DB, err = gorm.Open("mysql", "root:root@(127.0.0.1:3306)/2206a?charset=utf8mb4&parseTime=True&loc=Local")
	if err != nil {
		panic(err)
	} else {
		fmt.Println("数据库链接成功")
	}

	// 自动迁移
	DB.AutoMigrate(&UserCc{}, &Products{})
}
